package com.amoyt.project.controller.web;

import com.amoyt.project.annotations.ModuleLog;
import com.amoyt.project.constants.ResponseConstants;
import com.amoyt.project.domain.dto.query.ArticlePageQuery;
import com.amoyt.project.domain.res.Result;
import com.amoyt.project.service.admin.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Date: 2025/8/25
 * @Time: 16:39
 * @Author: TQ_QT
 * @Description:
 */
@RestController
@RequestMapping("/web/news")
@Tag(name = "新闻查看公共接口",description = "新闻接口")
public class NewsController {
    @Autowired
    private ArticleService articleService;

    /**
     * 新闻列表
     * @param pageQuery
     * @return
     */
    @GetMapping("/list")
    @Operation(summary = "新闻列表",method = "GET")
    public Result list(ArticlePageQuery pageQuery){
        if (pageQuery == null || pageQuery.getPage() == null || pageQuery.getPageSize() == null){
            return Result.error(ResponseConstants.SYSTEM_ERROR);
        }
        //设置为新闻
        pageQuery.setCategory(ArticlePageQuery.CATEGORY_NEWS);
        pageQuery.setIsOpen(ArticlePageQuery.IS_OPEN);
        pageQuery.setIsPublished(ArticlePageQuery.IS_PUBLISHED);
        return articleService.list(pageQuery);
    }

    /**
     * 新闻详情
     * @param articleId
     * @return
     */
    @GetMapping("/detail/{articleId}")
    @Operation(summary = "新闻详情（暂时弃用）",method = "GET")
    public Result detail(@PathVariable String articleId){
        if (articleId == null){
            return Result.error(ResponseConstants.SYSTEM_ERROR);
        }
        return articleService.queryArticleDetail(articleId);
    }

    @GetMapping("/detail-new/{articleId}")
    @Operation(summary = "新闻详情",method = "GET")
    public Result detailNew(@PathVariable String articleId){
        if (articleId == null){
            return Result.error(ResponseConstants.SYSTEM_ERROR);
        }
        return articleService.queryArticleDetailNew(articleId);
    }

}
